﻿<UserControl x:Class="ScrumFactory.Projects.MyDay"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:props="clr-namespace:ScrumFactory.Projects.Properties" 
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition"
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             
             x:Name="thisView"
             
             SF_Comp:CommandBehavior.RoutedEventName="Loaded"
            SF_Comp:CommandBehavior.TheCommandToRun="{Binding OnLoadCommand}">
    
    <UserControl.Resources>

        <Style x:Key="EventDescriptionTextBlock" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding EventType}" Value="0">
                    <Setter Property="TextBlock.Text" Value="{x:Static props:Resources.Project_start}"/>
                 </DataTrigger>
                <DataTrigger Binding="{Binding EventType}" Value="1">
                    <Setter Property="TextBlock.Text" Value="{Binding SprintNumber, StringFormat={x:Static props:Resources.Sprint_N_start}}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding EventType}" Value="2">
                    <Setter Property="TextBlock.Text" Value="{x:Static props:Resources.PProject_end}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="NoItemsTextBlock" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
            <Setter Property="Text" Value="{x:Static props:Resources.no_items}"/>
            <Setter Property="Foreground" Value="{StaticResource SubTextBrush}"/>            
            <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding .}" Value="0">
                    <Setter Property="TextBlock.Visibility" Value="Visible"/>
                </DataTrigger>                
            </Style.Triggers>
        </Style>

    </UserControl.Resources>
    
    <Grid>
        <StackPanel Orientation="Vertical" Margin="5">

            <TextBlock Text="{Binding TodayHeader}"
                   FontWeight="DemiBold"
                    Foreground="{StaticResource LabelBrush}"
                    FontSize="{StaticResource BigFontSize}"/>

            <TextBlock Text="{x:Static props:Resources.My_tasks}" Style="{StaticResource GroupTextBlock}" Margin="0,10,0,5"/>
            <ListView
                x:Name="myTasksList"
            Style="{StaticResource ListViewNoHeader}"
            SF_Helpers:ListViewColumnsExtension.Stretch="True"     
            SF_Helpers:ItemActivation.ActivationMode="Both"            
            SF_Helpers:ItemActivation.TheCommandToRun="{Binding ShowTaskDetailCommand}" 
            ItemsSource="{Binding MyTasks}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="30">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Image Style="{StaticResource TaskTypeImage}" DataContext="{Binding TaskType}"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock >
                                    <Hyperlink Command="{Binding Model.ShowTaskDetailCommand, ElementName=thisView}" CommandParameter="{Binding .}">
                                        <TextBlock Text="{Binding TaskName}" TextTrimming="CharacterEllipsis"/>    
                                    </Hyperlink>
                                </TextBlock>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="70">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock 
                                    HorizontalAlignment="Right"
                                    FontSize="{StaticResource SmallFontSize}"
                                    Text="{Binding DaysOpened, StringFormat={x:Static props:Resources.N_days}}" FontStyle="Italic" Foreground="{StaticResource SubTextBrush}"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
            <TextBlock Style="{StaticResource NoItemsTextBlock}" DataContext="{Binding ElementName=myTasksList, Path=Items.Count}"/>
            
            <TextBlock Text="{x:Static props:Resources.My_observer_tasks}" Style="{StaticResource GroupTextBlock}" Margin="0,15,0,5"/>
            <ListView
                x:Name="myOwnedTaskList"
            Style="{StaticResource ListViewNoHeader}"
            SF_Helpers:ItemActivation.ActivationMode="Both"            
            SF_Helpers:ItemActivation.TheCommandToRun="{Binding ShowTaskDetailCommand}"
            SF_Helpers:ListViewColumnsExtension.Stretch="True"
            ItemsSource="{Binding MyOwnedTasks}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="30">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Image Style="{StaticResource TaskTypeImage}" DataContext="{Binding TaskType}"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock >
                                        <Hyperlink Command="{Binding Model.ShowTaskDetailCommand, ElementName=thisView}" CommandParameter="{Binding .}">
                                            <TextBlock Text="{Binding TaskName}" TextTrimming="CharacterEllipsis"/>    
                                        </Hyperlink>
                                        <LineBreak/>
                                        <TextBlock Text="{Binding TaskAssigneeUId}" FontSize="{StaticResource SmallFontSize}" Foreground="{StaticResource SubTextBrush}" TextTrimming="CharacterEllipsis"/>
                                </TextBlock>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="70">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock 
                                    FontSize="{StaticResource SmallFontSize}"
                                    HorizontalAlignment="Right"
                                    Text="{Binding DaysOpened, StringFormat={x:Static props:Resources.N_days}}" FontStyle="Italic" Foreground="{StaticResource SubTextBrush}"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
            <TextBlock Style="{StaticResource NoItemsTextBlock}" DataContext="{Binding ElementName=myOwnedTaskList, Path=Items.Count}"/>

            <TextBlock Text="{x:Static props:Resources.Important_dates}" Style="{StaticResource GroupTextBlock}" Margin="0,15,0,5"/>
            <ListView
                x:Name="eventList"
            Style="{StaticResource ListViewNoHeader}"
            SF_Helpers:ListViewColumnsExtension.Stretch="True"
            ItemsSource="{Binding ProjectEvents}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="30">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Image Style="{StaticResource EventTypeImage}" DataContext="{Binding EventType}"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock>
                                    <Hyperlink Command="{Binding Model.ShowProjectDetailCommand, ElementName=thisView}" CommandParameter="{Binding ProjectUId}">
                                        <TextBlock Style="{StaticResource EventDescriptionTextBlock}" TextTrimming="CharacterEllipsis"/>    
                                    </Hyperlink>
                                    <LineBreak/>
                                    <TextBlock Text="{Binding ProjectName}" TextTrimming="CharacterEllipsis" FontSize="{StaticResource SmallFontSize}" Foreground="{StaticResource SubTextBrush}"/>
                                </TextBlock>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Width="70">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock                                     
                                    FontWeight="Bold"
                                    HorizontalAlignment="Right"
                                    Text="{Binding DaysLeft, StringFormat={x:Static props:Resources.N_days}}" FontStyle="Italic" Foreground="{StaticResource SubTextBrush}"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>

            <TextBlock Style="{StaticResource NoItemsTextBlock}" DataContext="{Binding ElementName=eventList, Path=Items.Count}"/>


        </StackPanel>

        <ContentControl Style="{StaticResource LoadingAnimationContent}"/>

    </Grid>
    

    

</UserControl>
